<?php

use App\Models\Article;
// use Artisan;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


// Route::get('/', function () {
//     // print_r(menus('front-nav'));exit;
//     return view('index');
// });
Route::get('{locale?}/', 'IndexController@index')
    ->where([
        'locale' => '^(en|cn|EN|CN)'
    ])
    ->name('home.index');

$prefix = App::getLocale();



Route::group(['middleware' => 'language', 'prefix' => $prefix], function() {
    Route::get('p/{slug}', 'PageController@index')->name('page.index');
    // Route::get('/editorial/{id}', 'PageController@editorial');
    Route::get('/category/{slug}', 'NewsController@index')->name('news.home');
    Route::get('/news/{slug}', 'NewsController@new')->name('news.show');
    Route::get('/notice/{id}', 'NewsController@notice')->name('notice.show');

    Route::get("/current/issue", 'IssueController@current')->name('issue.current');
    Route::get("/volumes/{type?}", 'VolumeController@list')->where([
        'type' => '^(table|years|list)$'
    ])->name('volume.show');
    Route::get("/volume/{year}", 'VolumeController@index')->where([
    	'year' => '\d+'
    ])->name('volume.index');

    Route::get("/issue/{issue}", 'IssueController@index')->name('issue.index');
    Route::get("/article/press", 'ArticleController@press');
    Route::get("/article/search", 'ArticleController@search')->name('search');
    Route::get("/article/{id}", 'ArticleController@index')->name('article.index');
    Route::get("/article/{id}/html", 'ArticleController@html')->name('article.html');
    Route::get("/article/{id}/{type}", 'ArticleController@downloadFile')->name('article.filedownload');
    Route::post("/article/search", 'ArticleController@search')->name('article.search');
    Route::get("/article/ref_export/{id}/{type}", 'ArticleController@downloadRef')
        ->where([
            'type' => '^(bibtex|endnote|reference_manager|procite|refworks)$'
        ])
        ->name('article.export_ref');

    Route::get("/articles/refs", 'ArticleController@downloadMultipleRef')
        ->where([
            'type' => '^(bibtex|endnote|reference_manager|procite|refworks)$'
        ])
        ->name('article.export_refs');


    Route::get("/email/alert", 'AlertController@index')->name('alert.index');
    Route::post("/email/alert/save", 'AlertController@save')->name('alert.save');
    Route::get("/email/alert/captcha/{tmp}", 'AlertController@captcha')->name('alert.captcha');

    Route::get("/collections", 'CollectionController@index')->name('collection.index');
    Route::get("/collection/articles/{id}", 'CollectionController@articles')->name('collection.article');

    Route::get("/article_press/list", 'InPressArticleController@list')->name('press_article.list');
    Route::get("/article_press/index/{id}", 'InPressArticleController@index')->name('press_article.index');
    Route::get("/article_press/download/{id}/{type}", 'InPressArticleController@downloadFile')->name('press_article.download')
        ->where([
            'type' => '^(pdf)$'
        ]);
    
    Route::get("/press_article/ref_export/{id}/{type}", 'InPressArticleController@downloadRef')
        ->where([
            'type' => '^(bibtex|endnote|reference_manager|procite|refworks)$'
        ])
        ->name('press_article.export_ref');

    Route::get("/press_article/refs", 'InPressArticleController@downloadMultipleRef')
        ->where([
            'type' => '^(bibtex|endnote|reference_manager|procite|refworks)$'
        ])
        ->name('press_article.export_refs');

});
Route::get('/EN/{d1}/{d2}', 'ArticleController@doi')->name('doi.link');
Route::get('/en/{d1}/{d2}', 'ArticleController@doi')->name('doi.slink');

// Route::get("/api/article/upload", 'ApiController@post')->name('article.post');

Route::get('/test', function(){
    print_r(Artisan::call('xml:html'));exit;
    print_r(Article::getBaiduCitesList());exit;

    print_r(Artisan::call('sync:baidu:citation'));exit;
    print_r(Artisan::call('fetch:issue_img', ['id' => 1362]));exit;
    print_r(Artisan::call('fetch:pdf', ['id' => 1539]));exit;
    print_r(Artisan::call('fetch:article', ['id' => 3858]));exit;
    print_r(Artisan::call('fetch:article', ['--issue' => 1288]));exit;
});

